<template>
	<view class="container">
		<TopBtn :title="'常用回复'"></TopBtn>
		<searchBar :placeholder="'回复内容'" @chenge="chenge"></searchBar>
		<view class="listBox">
			<view class="list" v-for="n,index in list" :key="n.id">
				<view class="">
					<view class="title flex-center">
						<image src="@/static/CommonTools/hf.png" mode=""></image>
						常用{{index+1}}
					</view>
					<view class="text rowShow_2">
						{{n.content}}
					</view>
					<view class="btnBox">
						<view class="" @click="del(n.id)">
							<image src="@/static/CommonTools/bj.png" mode=""></image>
							删除
						</view>
						<view class="" @click.stop="openPup(2,n.id)">
							<image src="@/static/CommonTools/sc.png" mode=""></image>
							编辑
						</view>
					</view>
				</view>
			</view>
		</view>
		<uni-popup ref="popup" type="bottom">
			<view class="pupbox">
				<view class="title">
					<view class="close" @click="closePup()">
						取消
					</view>
					{{type==1?'添加':"修改"}}回复
					<view class="add" @click="Submit()">
						确认
					</view>
				</view>
				<view class="">
					<textArea v-model="data.content" :inputNane="data.content" :maxNum="50"></textArea>
				</view>
			</view>
		</uni-popup>
		<view class="CommonToolsbtn flex-center-center" @click="openPup(1)">
			添加常用回复
		</view>
		<view class="kong">

		</view>
	</view>
</template>

<script>
	import {
		getDoctorCommonRepliesPage,
		createDoctorCommonReplies,
		getDoctorCommonReplies,
		updateDoctorCommonReplies,
		deleteDoctorCommonReplies
	} from '@/api/commonTools'
	export default {
		data() {
			return {
				act: "1",
				value: "",
				list: [],
				type: "",
				data: {
					content: "",
				},
				request: {
					pageNo: 1,
					pageSize: 10,
				},
				maxNum: "",
			};
		},
		onLoad() {
			this.getDoctorCommonRepliesPage()
		},
		onReachBottom() {
			if (this.maxNum <= this.request.pageNo) return
			this.request.pageNo = this.request.pageNo + 1
			this.getDoctorCommonRepliesPage()
		},
		methods: {
			chenge(e) {
				this.request.content = e
				this.list = []
				this.request.pageNo = 1
				this.getDoctorCommonRepliesPage()
			},
			Submit() {
				if (this.type == 1) {
					uni.showLoading({
						title: '提交中',
						mask: true
					})
					createDoctorCommonReplies(this.data).then(res => {
						setTimeout(() => {
							uni.hideLoading()
							this.request.pageNo = 1
							this.list = []
							this.closePup()
							this.getDoctorCommonRepliesPage()
						}, 200)
					})
				} else if (this.type == 2) {
					uni.showLoading({
						title: '提交中',
						mask: true
					})
					updateDoctorCommonReplies(this.data).then(res => {
						setTimeout(() => {
							uni.hideLoading()
							this.request.pageNo = 1
							this.list = []
							this.closePup()
							this.getDoctorCommonRepliesPage()
						}, 200)
					})
				}
			},
			del(id) {
				var _this = this
				uni.showModal({
					title: '提示',
					content: '是否确认删除',
					success: function(res) {
						if (res.confirm) {
							deleteDoctorCommonReplies(id).then(res => {
								_this.request.pageNo = 1
								_this.list = []
								_this.getDoctorCommonRepliesPage()
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					},
				})
			},
			openPup(e, id) {
				this.type = e
				if (id) {
					this.getDoctorCommonReplies(id)
				}
				this.$refs.popup.open('bottom')
			},
			closePup() {
				this.$refs.popup.close()
				this.data = {}
			},
			getDoctorCommonReplies(id) {
				this.data = {}
				getDoctorCommonReplies({
					id: id
				}).then(res => {
					this.data = res.data
				})
			},
			getDoctorCommonRepliesPage() {
				getDoctorCommonRepliesPage(this.request).then(res => {
					this.list.push(...res.data.list)
					let num = res.data.total / this.request.pageSize
					if (num.toString().includes('.')) {
						num = Math.ceil(num)
					}
					this.maxNum = num
				})
			},
			// getDoctorCommonRepliesPage() {
			// 	getDoctorCommonRepliesPage().then(res => {
			// 		this.list = res.data.list
			// 	})
			// },
			goinfo(id) {
				if (id) {
					uni.navigateTo({
						url: `/pages/prescription/details/details?id=${id}`,
					})
				}
			},
		}
	}
</script>

<style lang="less" scoped>
	.pupbox {
		width: 750rpx;
		height: 522rpx;
		background: #ffffff;
		border-radius: 50rpx 50rpx 0rpx 0rpx;
		padding: 30rpx 50rpx;
		box-sizing: border-box;
		background-size: 100% 100%;

		.title {
			font-size: 36rpx;
			font-weight: bold;
			color: #333333;
			position: relative;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.add {
				font-weight: 500;
				font-size: 28rpx;
				color: #3E6EFE
			}

			.close {
				font-weight: 500;
				font-size: 28rpx;
				color: #999999;
			}

		}

		.messageList {
			margin-top: 1em;

			margin-top: 1em;

			.scroll-view_H {
				white-space: nowrap;
				width: 100%;
			}

			.messageinfo {
				display: inline-block;
				width: 287rpx;
				height: 220rpx;
				border: 2px solid #eeeeee;
				border-radius: 15rpx;
				margin-right: 25rpx;
				padding: 20rpx;
				box-sizing: border-box;
				font-size: 26rpx;
				font-weight: 500;
				color: #999999;
				vertical-align: top;
			}

			.text {
				height: 100%;
				display: flex;
				align-items: center;
				white-space: wrap;
				white-space: pre-wrap;
				/* css-3 */
				white-space: -moz-pre-wrap;
				/* Mozilla, since 1999 */
				white-space: -pre-wrap;
				/* Opera 4-6 */
				white-space: -o-pre-wrap;
				/* Opera 7 */
				word-wrap: break-word;
				/* Internet Explorer 5.5+ */
			}

			.act {
				border: 4rpx solid #aa75fa;
				color: #7e67fd;
			}
		}

		// 多行文本输入框
		/deep/.uni-easyinput__content {
			border: none;
		}

		// 多行文本输入框
		/deep/.is-textarea {
			background-color: #f9f9f9 !important;
			margin: 23rpx 0 40rpx;

		}

		/deep/.is-input-border {
			border-radius: 20rpx;
		}

		/deep/.uni-easyinput__placeholder-class {
			font-size: 28rpx;
		}
	}

	.listBox {
		margin-top: 43rpx;
		padding: 0 30rpx;

		.btnBox {
			display: flex;
			align-items: center;
			justify-content: right;

			view {
				font-weight: 500;
				font-size: 26rpx;
				color: #999999;
				margin-left: 40rpx;
				display: flex;
				align-items: center;

				image {
					width: 31rpx;
					height: 29rpx;
					margin-right: 10rpx;
				}
			}
		}

		.list {
			width: 690rpx;
			height: 182rpx;
			background: #FFFFFF;
			border-radius: 30rpx;
			padding: 20rpx;
			box-sizing: border-box;
			display: flex;
			align-items: center;
			margin-bottom: 30rpx;

			&>view {
				width: 100%;
			}

			.title {
				font-size: 32rpx;
				font-weight: bold;
				color: #333333;

				image {
					width: 30rpx;
					height: 30rpx;
					margin-right: 17rpx;
				}
			}

			.text {
				width: 100%;
				font-size: 28rpx;
				color: #333333;
				margin-top: 12rpx;
			}


		}
	}
</style>